package com.utonw.carloan.adpter.main;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.utonw.carloan.R;
import com.utonw.carloan.bean.main.MainGuideBean;

import java.util.ArrayList;

/**
 * Created by SEELE on 2017/3/21.
 */

public class MainGuideAdapter extends RecyclerView.Adapter<MainGuideAdapter.MyViewHolder>{
    private Context mContext;
    private ArrayList<MainGuideBean> mData;
    private MyClickListener mClickListener;

    public void setOnItemClickListener(MyClickListener clickListener) {
        mClickListener = clickListener;
    }

    public MainGuideAdapter(Context context) {
        mContext = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_recycler_main_guide,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.mIcon.setImageResource(mData.get(position).getIcon());
        holder.mTitle.setText(mData.get(position).getTitle());
        if (mData.get(position).isShowMessageTips()){
            holder.mTips.setVisibility(View.VISIBLE);

        }else {
            holder.mTips.setVisibility(View.GONE);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mClickListener.onItemClickListener(mData.get(position).getTitle());
            }
        });


    }

    @Override
    public int getItemCount() {
        return mData!=null&&mData.size()>0?mData.size():0;
    }

    public void setData(ArrayList<MainGuideBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private ImageView mIcon;
        private TextView mTitle;
        private TextView mTips;

        public MyViewHolder(View itemView) {
            super(itemView);
            mIcon = (ImageView) itemView.findViewById(R.id.iv_guide_main);
            mTitle = (TextView) itemView.findViewById(R.id.tv_guide_title);
            mTips = (TextView) itemView.findViewById(R.id.tv_tips_num);
        }
    }

    public interface MyClickListener{

        void onItemClickListener(int titleId);

    }
}
